<?

  chdir('..');
  include_once('lib/genlib.php');
  include_once('etc/config.php');
  include_once('lib/cq-io.php');
  include_once('lib/cq-url.php');
  
  $viewtemplate = 'themes/default/page.default.php';

  if ($config['environment'] == 'production') 
  {
    include('etc/errors/403.php');
    die();
  }
  
  function ExecCodeTemplate($template, $name, $file)
  {
    $templateFilename = 'scripts/template.'.$template.'.php';
    if (!file_exists($templateFilename))
    {
      print('<div>ERROR: template "'.$templateFilename.'" not found!</div>');    
    }
    else
    {
      $code = implode('', file($templateFilename));
      $fileCode = str_replace('*ENAME*', $name, $code);
      print('<h3>writing code to '.$file.'</h3><pre>'.htmlentities($fileCode).'</pre>');
      WriteToFile($file, $fileCode);
    }
  }
  
  ob_start();

  $config['pagetitle'] = 'Colloq Config Tools';

  $screen = getDefault($_REQUEST['cmd'], 'menu');
  include('scripts/screen.'.$screen.'.php');
  
  if ($screen != 'menu')
    print('<br/><br/><br/>&lt; <a href="javascript:history.back();">go back</a>');

  $content = ob_get_clean();
  
  if (file_exists($viewtemplate))
    include($viewtemplate);
  else
    print($viewtemplate);

?>